const http = require('http');
const fs = require('fs');
const path = require('path');

http.createServer(function(req,res){
   const url = new URL("http://localhost:3000" + req.url);
   if(url.pathname == "/login"){
        console.log("username:",url.searchParams.get("username"));
        res.end("suc");
   }else{
    fs.readFile(path.join("public",req.url),function(err,data){
        if(err){
            console.log('读取文件失败');
            res.end();
            return;
        }
        res.write("123");
        res.end(123);
    });
   }
   
    // res.write(`
    //     <html>
    //         <head>
    //             <meta charset="utf-8">
    //         </head>
    //         <body>
    //             <h1>Hello，你好</h1>
    //         </body>
    //     </html>
    // `);
    // res.end();
}).listen(3000);
console.log("服务器启动成功");